package ModelLayer;
import java.util.ArrayList;

public class CustomerContainer {
    private ArrayList<Customer> customerContainer;
    private static CustomerContainer instance;
    private Customer cObject;
    public CustomerContainer()
    {
        customerContainer = new ArrayList<Customer>();
    }

    public static CustomerContainer getInstance()
    {
        if(instance == null)
        {
            instance = new CustomerContainer();
        }
        return instance;
    }

    public Customer findCustomerByCpr(String cpr){
        cObject = null;
        int index = 0;
        boolean found = false;
        while(index < customerContainer.size() && !found)
        {
            if(customerContainer.get(index).getCpr() == cpr)
            {
                cObject = customerContainer.get(index);
                found = true;
            }
            else
            {
                index++;
            }
        }//end while
        return cObject;

    }

    public boolean addCustomer(Customer c)
    {
        boolean added = false;
        if(findCustomerByCpr(c.getCpr()) == null)
        {
            customerContainer.add(c);
            added=true;
        }
        return added;
    }

    public boolean deleteCustomerByCpr(String cpr)
    {
        if(customerContainer.contains(findCustomerByCpr(cpr)))
        {
            customerContainer.remove(findCustomerByCpr(cpr));
            return true;
        }
        else
        {
            return false;
        }
    }
}
